package com.xly.webclick.vm

import android.databinding.ObservableField
import android.os.Bundle
import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.input.input
import com.afollestad.materialdialogs.list.listItemsSingleChoice
import com.xly.webclick.R
import com.xly.webclick.base.BaseViewModel
import com.xly.webclick.model.AddressData
import com.xly.webclick.presenter.GetAddressPresenter
import com.xly.webclick.vi.GetAddressInterface
import com.xly.webclick.view.ManageTaskActivity

/**
 * Created by xuleyuan on 2018/8/21
 */

class ManageTaskViewModel(view: ManageTaskActivity) : BaseViewModel(view), GetAddressInterface {

    override fun onGetAddress(addressData: AddressData?) {
        initDialog()
    }

    override fun onAddressError() {

    }

    val url = ObservableField<String>("")
    val engineer = ObservableField<String>("")
    val keyWord = ObservableField<String>("")
    val area = ObservableField<String>("")
    val page = ObservableField<String>("")
    val taskTime = ObservableField<String>("")
    val limit = ObservableField<String>("")

    val addressPresenter = GetAddressPresenter();

    override fun onResume() {

    }

    override fun onDestroy() {
        super.onDestroy()
        addressPresenter.detch()
    }
    override fun initData(savedInstanceState: Bundle?) {
        addressPresenter.attach(this)
        addressPresenter.doRequest()
    }

    private fun initDialog() {

    }

    fun setUrl() {
        MaterialDialog(getActivity()).title(R.string.input_url).input { materialDialog, charSequence -> url.set(charSequence.toString()) }.positiveButton(R.string.OK).show()
    }

    fun setEngineer() {
        val myItems = listOf("百度", "谷歌", "神马", "搜狗", "必应")
//
        MaterialDialog(getActivity())
                .title(R.string.select_engineer)
                .listItemsSingleChoice(items = myItems)
                { _, index, text ->
                    engineer.set(text)
                }
                .show()
    }

    fun setKeyWord() {
        MaterialDialog(getActivity()).title(R.string.input_key_word).input { materialDialog, charSequence -> keyWord.set(charSequence.toString()) }.positiveButton(R.string.OK).show()
    }

    fun setArea() {

    }

    fun setPage() {

    }

    fun setTaskTime() {

    }

    fun setTaskLimit() {

    }
}
